﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fitment
{
    public partial class SelectHouse : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int userID = Convert.ToInt32(Session["User_ID"]);   //用于获取用户id
                MyLinqDataContext data = new MyLinqDataContext();   //使用linq进行查询
                var search =(from p in data.ProjectInfo
                             from q in data.HouseInfo
                             where p.House_ID == q.House_ID && q.User_ID == userID && Convert.ToDateTime(p.StartDate) != null
                             select  q.House_ID).Distinct();
                if (search.Count()==0)
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "提示", "<script>alert('你还没有进行日期选择，请指定工程开始时间！');</script>");
                    this.submit.Visible = false;   //将按钮提交赋空
                }
                this.select.DataSource = search.ToList();   //选择数据源
                this.select.DataBind();   //绑定数据源
            }
            
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            int strHouse_ID = Convert.ToInt32(this.select.Text);
            string url = String.Format("ShowProject.aspx?id={0}",strHouse_ID);
            Response.Redirect(url);   //重定向到特定工程中
            
       }
    }
}
